package com.ywy.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

/**
 * 邮件配置类
 *
 * @author ywy
 * @date 2022/8/29 10:33
 */
@Configuration
public class MailConfig {
    @Value("${mail.host}")
    private String host;//邮件服务器主机

    @Value("${mail.port}")
    private Integer port;//SMTP端口

    @Value("${mail.username}")
    private String username;//用户名

    @Value("${mail.password}")
    private String password;//密码

    /**
     * 获取邮件发送实例
     *
     * @return
     */
    @Bean
    public MailSender mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setPort(port);
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        return mailSender;
    }
}
